Conversation
| """Set all variables to random values and return the flat vector.""" | ||
| n = scope.total_var_size | ||
| x0 = rng.uniform(low, high, size=n) | ||
| scope.set_values(x0) |
There was a problem hiding this comment.
why set values here? does this function have to accept scope?
| np.testing.assert_allclose(fn.forward(), 3.0 * x0) | ||
|
|
||
|
|
||
| def test_left_matmul_parameter_jacobian(scope, rng): |
There was a problem hiding this comment.
In every test with parameters, set new values of the parameters and verify derivatives again.
| import scipy.sparse | ||
| import sparsediffpy as sp | ||
| from tests.utils import NumericalDerivativeChecker, random_point | ||
|
|
There was a problem hiding this comment.
Add parameter tests for test_right_matmul.
| checker = NumericalDerivativeChecker(fn, scope) | ||
| checker.check_jacobian(random_point(scope, rng)) | ||
|
|
||
|
|
There was a problem hiding this comment.
Add test where the parameter appears on the right side of the multiplication
| import sparsediffpy as sp | ||
| from tests.utils import NumericalDerivativeChecker, random_point | ||
|
|
||
|
|
There was a problem hiding this comment.
What atoms does this file test? Should also add parameter check.
| import sparsediffpy as sp | ||
| from tests.utils import NumericalDerivativeChecker, random_point | ||
|
|
||
|
|
There was a problem hiding this comment.
Add 3 tests (one axis each) for summing matrix parameters
| checker.check_jacobian(random_point(scope, rng)) | ||
|
|
||
|
|
||
| def test_trace_hessian(scope, rng): |
There was a problem hiding this comment.
Do something nonlinear here
| import sparsediffpy as sp | ||
| from tests.utils import NumericalDerivativeChecker, random_point | ||
|
|
||
|
|
There was a problem hiding this comment.
Add tests with constant and parameter on the right
| import numpy as np | ||
| import sparsediffpy as sp | ||
| from tests.utils import NumericalDerivativeChecker, random_point | ||
|
|
There was a problem hiding this comment.
Add forward and jacobian tests for vstack/hstack of 3 expressions: one nonlinear, one parameter, and one constant
| np.testing.assert_allclose(fn.forward(), x_val * y_val) | ||
|
|
||
|
|
||
| def test_multiply_matrices_jacobian(scope, rng): |
There was a problem hiding this comment.
Also add this test but when you swap order of X and Y
|
|
||
| # ----------------------------------------------------------------------- | ||
| # 4. Broadcast heavy: a * X + r + c | ||
| # a: scalar (1,1), X: matrix (3,2), r: row (1,2), c: column (3,1) |
There was a problem hiding this comment.
Also add test for just r + c (without the first term a * X)
|
|
||
|
|
||
| # ----------------------------------------------------------------------- | ||
| # 6. Hstack mixed: hstack([sin(x), A @ x, y]) |
There was a problem hiding this comment.
Add a test like this with one of them being a parameter
| fn_f = sp.compile(f) | ||
| fn_g = sp.compile(g) | ||
|
|
||
| x0 = random_point(scope, rng) |
There was a problem hiding this comment.
It is confusing that random_point sets the value of the variables in that scope
Very much work in progress